package com.yonyou.crm.base.doc.service;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yonyou.crm.base.doc.entity.BaseDocDetailVO;
import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.iuap.context.InvocationInfoProxy;

@Service
public class BaseDocDetailBizServiceImpl extends BaseBizServiceImpl<BaseDocDetailVO> {
	
	public BaseDocDetailVO insertbaseDocDetail(BaseDocDetailVO vo){
		return super.saveVO(vo);
	}
	
	public int deletebaseDocDetailBybaseDocIds(String[] ids){
		return super.batchDeleteByIDs(BaseDocDetailVO.class, ids);
	}
	
	public int deletebaseDocDetailByIds(BaseDocDetailVO vo){
		return super.deleteVO(vo);
	}
	
	public BaseDocDetailVO updatebaseDocDetail(BaseDocDetailVO vo){
		return super.updateVO(vo);
	}
	
	public void batchInsertBaseDocDetail(List<BaseDocDetailVO> baseDocDetailList){
		beforeBatchInsert(baseDocDetailList);
		dao.saveSql(BaseDocDetailVO.class, "batchInsert", baseDocDetailList);
	}
	
	private void beforeBatchInsert(List<BaseDocDetailVO> baseDocDetailList) {
        Long loginUserID = new Long(InvocationInfoProxy.getParameter("id"));
        Date date = new Date();
        for (BaseDocDetailVO vo : baseDocDetailList) {
        	vo.setTenantId(new Long(InvocationInfoProxy.getTenantid()));
        	vo.setSysCreatedTime(date);
        	vo.setSysCreatedUserId(loginUserID);
        	vo.setSysModifiedTime(date);
        	vo.setSysModifiedUserId(loginUserID);
        }
    }
	
	public void batchUpdateBaseDocDetail(List<BaseDocDetailVO> baseDocDetailList){
		beforeBatchUpdate(baseDocDetailList);
        dao.updateSql(BaseDocDetailVO.class, "batchUpdate", baseDocDetailList);
	}
	
	private void beforeBatchUpdate(List<BaseDocDetailVO> baseDocDetailList) {
        Long loginUserID = new Long(InvocationInfoProxy.getParameter("id"));
        Date date = new Date();
        for (BaseDocDetailVO bvo : baseDocDetailList) {
            bvo.setSysModifiedTime(date);
            bvo.setSysModifiedUserId(loginUserID);
        }
    }	
	
	public Object selectFieldsByIds(Object[] ids) {
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("ids", ids);
		return dao.selectList(BaseDocDetailVO.class, "selectFieldsByIds", para);
	}
	
	public int deleteBaseDocDetailByIds(Object[] ids){
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("ids", ids);
		para.put("deletedUserId", new Long(InvocationInfoProxy.getParameter("id")));
		para.put("deletedTime", new Date());
		return dao.updateSql(BaseDocDetailVO.class, "batchDelete", para);
	}
}
